<?php
try{
    //建立连接
   include __DIR__.'/../includes/DatabaseConnection.php';
   include_once __DIR__.'/../includes/DatabaseFunctions.php';

    $sql = 'SELECT `joke`.`id`,`joketext`,`name`,`email` 
    FROM `joke` INNER JOIN `author` ON `authorid`=`author`.`id`';
    // $result = $pdo->query($sql);

    // foreach ($result as $row){
    //     $jokes[] = ['id'=>$row['id'],'joketext'=>$row['joketext']];
    // }


    $jokes = $pdo->query($sql);

    $title = "笑话列表";

    $totalJokes = totalJokes($pdo);

    ob_start(); //开始输出缓存

    include __DIR__.'/../templates/jokes.html.php';
    $output = ob_get_clean();
    
}catch(PDOException $e){
    $output = "不能连接到数据库".$e->getMessage().' in '.$e->getFile().':'.$e->getLine();
}
include __DIR__.'/../templates/layout.html.php';